package main

import (
	"fmt"
	"net/http"

	"github.com/gorilla/websocket"
)

//参考WEB服务实现
var html = `<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>magedu</title>
</head>
<body>
	<h1>马哥教育www.magedu.com -- http库</h1><br>
	WebSocket测试 ws://127.0.0.1:9999/wsecho
</body>
</html>`

var upgrader = websocket.Upgrader{}

func home(w http.ResponseWriter, request *http.Request) {
	fmt.Printf("请求=%v\n", request)
	w.Header().Add("X-Server", "magedu.com")
	w.Write([]byte(html))
}

func wsecho(w http.ResponseWriter, request *http.Request) {
	// TODO
}

func main() {
	// URL映射刀handler, handler函数2个参数一进一出
	http.HandleFunc("/", home)   // HTTP协议处理
	http.HandleFunc("/", wsecho) // ws协议处理
	http.ListenAndServe("0.0.0.0:9999", nil)
}
